<?php
defined('IN_IXDCW') or exit('Access Denied');
$menus = array (
    array('图片列表', '?moduleid='.$moduleid.'&file='.$file),
);
$businessPictureDb = Db('businessPicture');
$this_forward = '?moduleid='.$moduleid.'&file='.$file;

if (in_array($action, array(''))) {
	if($kw) {
		if ($kwType == 'username') {
			$memberDb = Db('member');
			$user = $memberDb->getByUsername($kw);
			if (!$user) {
				msg('不正确的用户名');
			}
			$condition .= " and p.userid={$user['userid']}";
		}
	}
	$order = ' order by ';
	switch($orderType) {
		case 'itemidAsc':
			$order .= ' p.itemid ASC ';
			break;
		default:
			$order .= ' p.itemid DESC ';
			break;
	}
}


switch($action) {
	case 'delete':
		$itemid or msg('不正确的传入ID');
		$item = $businessPictureDb->getByItemid($itemid);
		$item or msg(ERR_MSG);
		if ($item) {
			Picture::deleteAll($item['thumb']);
			$businessPictureDb->deleteByItemid($itemid);
		}
		msg('删除成功', Env::referer());
		break;
	default:
		$num = $businessPictureDb->getCount($condition);
		$pn = new Pagination();
		$pn->recordsPerPage($pagesize);
		$pn->records($num);
		$condition .= $order;
		$condition .= " LIMIT " . ($pn->getPage() - 1) * $pagesize . ',' . $pagesize;
		$lists = $businessPictureDb->getList($condition);
		include tpl('business_picture', $module);
	break;
}